<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>

        <el-button type="danger" plain icon="el-icon-delete" size="mini" @click="handleClear" v-hasPermi="['system:log:remove']">清理</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="logList" border>
      <el-table-column label="ID" align="center" prop="id"/>
      <el-table-column label="部门编号" align="center" prop="bmbh"/>
      <el-table-column label="最近销售时间" align="center" prop="time"/>
      <el-table-column label="同步条数" align="center" prop="size"/>
      <el-table-column label="同步结果" align="center" prop="result"/>
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:log:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
  </div>
</template>

<script>
import {listLog, delLog, clearLog} from "@/api/erp/jd_log";

export default {
  name: "Log",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 京东到家库存同步日志表格数据
      logList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: "id",
        isAsc: "desc",
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询京东到家库存同步日志列表 */
    getList() {
      this.loading = true;
      listLog(this.queryParams).then(response => {
        this.logList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认清理京东到家库存同步日志？').then(function () {
        return delLog(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 清理按钮操作 */
    handleClear() {
      this.$modal.confirm('是否确认清理京东到家库存同步日志？').then(function () {
        return clearLog();
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("清理成功");
      }).catch(() => {
      });
    }
  }
}
;
</script>
